package com.tmall.testgen.plugin.wizards.runinspring;

import java.lang.reflect.Method;

import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

import com.tmall.testgen.client.runinspring.RunInSpringUtil;
import com.tmall.testgen.common.bo.interact.back.InterceptInfo;
import com.tmall.testgen.plugin.ConsoleFactory;
import com.tmall.testgen.plugin.views.vo.SpringTree;
import com.tmall.testgen.plugin.views.vo.TreeParent;

/**
 * run in spring配置页
 * 
 * @author liuzx
 * 
 */

public class RunInSpringWizadPage extends WizardPage {
	private Text springFileText;
	private Text methodNameText;

	private Method testMethod;
	private String methodName;
	private SpringTree parasRoot;

	private SpringTree resultRoot;

	private TreeParent genCodeRoot;
	
	private TreeParent genCodeInterceptRoot;
    private TreeParent genCodeMockRoot;
	/**
	 * 入参树
	 */
	private TreeViewer parasTreeViewer;
	/**
	 * 计算结果树
	 */
	private TreeViewer resultTreeViewer;
	/**
	 * 测试结果树
	 */
	private TreeViewer genCodeTreeViewer;

	private InterceptInfo currentInfo;
	private String targetProjectPath;

	public RunInSpringWizadPage(String targetProjectPath,Method testMethod) {
		super("RunInSpringWizadPage");
		setTitle("本地测试");
		setDescription("");
		this.testMethod = testMethod;
		this.targetProjectPath=targetProjectPath;
		setPageComplete(true);
		try {
			methodName = RunInSpringUtil.getMethodShowName(testMethod);
			TreeCreator.initTree(this);
		} catch (Exception e) {
			ConsoleFactory.putError(e);
		}
	}

	public void updateDialog(Method testMethod) {
		this.testMethod = testMethod;
		try {
			methodName = RunInSpringUtil.getMethodShowName(testMethod);
			getMethodNameText().setText(methodName);
			TreeCreator.initTree(this, true);
			getParasTreeViewer().setInput(getParasRoot());
			getParasTreeViewer().refresh();
			getResultTreeViewer().setInput(getResultRoot());
			getResultTreeViewer().refresh();
			getGenCodeTreeViewer().refresh();
		} catch (Exception e) {
			ConsoleFactory.putError(e);
		}
	}

	/**
	 * @see IDialogPage#createControl(Composite)
	 */
	public void createControl(Composite parent) {
		Composite com = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		layout.makeColumnsEqualWidth = false;
		com.setLayout(layout);

		// HSF配置文件显示区
		ComCreator.createComHSF(com, this);
		// spring配置文件显示区
		ComCreator.createComConfig(com, this);

		ComCreator.createMockComClass(com, this);
		// 方法名显示区
		ComCreator.createComClass(com, this);

		// 入参出参输入显示区
		ComCreator.createComMethod(com, this);

		// 代码生成显示区
		ComCreator.createComGenCode(com, genCodeRoot, this);

		setControl(com);
	}

	public Text getSpringFileText() {
		return springFileText;
	}

	public void setSpringFileText(Text springFileText) {
		this.springFileText = springFileText;
	}

	public Method getTestMethod() {
		return testMethod;
	}

	public void setTestMethod(Method testMethod) {
		this.testMethod = testMethod;
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public SpringTree getParasRoot() {
		return parasRoot;
	}

	public void setParasRoot(SpringTree parasRoot) {
		this.parasRoot = parasRoot;
	}

	public SpringTree getResultRoot() {
		return resultRoot;
	}

	public void setResultRoot(SpringTree resultRoot) {
		this.resultRoot = resultRoot;
	}

	public TreeViewer getParasTreeViewer() {
		return parasTreeViewer;
	}

	public void setParasTreeViewer(TreeViewer parasTreeViewer) {
		this.parasTreeViewer = parasTreeViewer;
	}

	public TreeViewer getResultTreeViewer() {
		return resultTreeViewer;
	}

	public void setResultTreeViewer(TreeViewer resultTreeViewer) {
		this.resultTreeViewer = resultTreeViewer;
	}

	public TreeViewer getGenCodeTreeViewer() {
		return genCodeTreeViewer;
	}

	public void setGenCodeTreeViewer(TreeViewer genCodeTreeViewer) {
		this.genCodeTreeViewer = genCodeTreeViewer;
	}

	public InterceptInfo getCurrentInfo() {
		return currentInfo;
	}

	public void setCurrentInfo(InterceptInfo currentInfo) {
		this.currentInfo = currentInfo;
	}

	public TreeParent getGenCodeRoot() {
		return genCodeRoot;
	}

	public void setGenCodeRoot(TreeParent genCodeRoot) {
		this.genCodeRoot = genCodeRoot;
	}

	public Text getMethodNameText() {
		return methodNameText;
	}

	public void setMethodNameText(Text methodNameText) {
		this.methodNameText = methodNameText;
	}

	public String getTargetProjectPath() {
		return targetProjectPath;
	}

    public TreeParent getGenCodeInterceptRoot() {
        return genCodeInterceptRoot;
    }

    public void setGenCodeInterceptRoot(TreeParent genCodeInterceptRoot) {
        this.genCodeInterceptRoot = genCodeInterceptRoot;
    }

    public TreeParent getGenCodeMockRoot() {
        return genCodeMockRoot;
    }

    public void setGenCodeMockRoot(TreeParent genCodeMockRoot) {
        this.genCodeMockRoot = genCodeMockRoot;
    }

	
}